<link rel="stylesheet" href="<?php echo $this->getJsUrl('jquery-ui-1.12.1/jquery-ui.min.css')?>">
<style type="text/css">
.actype_list_item{margin-bottom:5px;padding:5px 0;border-bottom:1px dashed #888;}
.actype_list_item:after{clear:both;content:".";visibility:hidden;height:0;}
.ac_list_item_info{margin-right:10px;}
.item_btn_grp{float:right;}
.ac_list_item{padding:5px;margin-bottom:10px;border:1px dashed #888;}
.ac_list_item_title{margin-bottom:5px;font-weight:bold;font-size:16px;}
.ac_list_item_info{color:#999;font-size:12px;}
.ac_list_item_content{padding:5px 0;font-size:14px;}
.ac_list_item_opt{text-align:right;}
</style>
<div>
	<div id="messages"></div>
	

	
	<div>
		<div class="columns ">
			<div class="side-col" id="page:left" style="display: block;">
				<h3>商家公告管理</h3>
				<ul id="product_info_tabs" class="tabs">
					<li>
						<a href="javascript:;" onclick="switchTab(this, 1)" title="公告主题管理" class="tab-item-link active">
							<span><span class="changed" title="公告主题管理"></span><span class="error" title="This tab contains invalid data. Please solve the problem before saving."></span>商家公告主题管理</span>
						</a>
					</li>
					<li>
						<a href="javascript:;" onclick="switchTab(this, 2)" title="商家公告发布" class="tab-item-link">
							<span><span class="changed" title="商家公告发布"></span><span class="error" title="This tab contains invalid data. Please solve the problem before saving."></span>商家公告发布</span>
						</a>
					</li>
					<li>
						<a href="javascript:;" onclick="switchTab(this, 3)" title="商家公告管理" class="tab-item-link">
							<span><span class="changed" title="商家公告管理"></span><span class="error" title="This tab contains invalid data. Please solve the problem before saving."></span>商家公告管理</span>
						</a>
					</li>
				</ul>
			</div>
			<div class="main-col" id="content">
				<div class="main-col-inner">
					<div id="messages"></div>
					<!--<div class="content-header">
						<h3 class="icon-head head-products">tiantainde111 (Jackets)</h3>
						<div class="content-buttons-placeholder" style="width:0px;height:0px;">
							<div class="content-buttons-placeholder" style="width: 0px; height: 0px;">
								<p class="content-buttons form-buttons">
									<button title="Save" type="button" class="scalable save" style=""><span><span><span>Save</span></span></span></button>
								</p>
							</div>
						</div>
					</div>-->
					<div>
						<div id="tab_1">
							<div class="entry-edit">
								<div class="entry-edit-head">
									<h4 class="icon-head head-edit-form fieldset-legend">商家公告主题管理</h4>
								</div>
								<div class="fieldset fieldset-wide">
									<div id="actype_list">
										<?php
											$acTypes = $this->getAnnouncementType();
											foreach ($acTypes as $type) {?>
										<div id="type_<?php echo $type['type_id'];?>" class="actype_list_item">
											<span class="item_name"><?php echo $type['name'];?></span>
											<input type="text" class="item_val" value="" style="display:none;"/>
											<div class="item_btn_grp">
												<button class="item_btn_edit" onclick="typeHandler.edit(this)">编辑</button>
												<button class="item_btn_save" style="display:none;margin-left:5px;" onclick="typeHandler.save(this)">保存</button>
												<button class="item_btn_cancel" style="display:none;margin-left:5px;" onclick="typeHandler.cancel(this)">取消</button>
											</div>
										</div>
										<?php }?>
									</div>
									<div class="actype_list_item">
										<input type="text" class="item_val" style="display:none;"/>
										<div class="item_btn_grp">
											<button class="item_btn_create" onclick="typeHandler.create(this)">创建</button>
											<button class="item_btn_save" style="display:none;margin-left:5px;" onclick="typeHandler.saveCreate(this)">保存</button>
											<button class="item_btn_cancel" style="display:none;margin-left:5px;" onclick="typeHandler.cancelCreate(this)">取消</button>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div id="tab_2" style="display:none;">
							<div class="entry-edit">
								<div class="entry-edit-head">
									<h4 class="icon-head head-edit-form fieldset-legend">商家公告发布</h4>
								</div>
								<div class="fieldset fieldset-wide">
									<div class="hor-scroll">
										<table cellspacing="0" class="form-list">
											<tbody>
												<tr>
													<td class="label"><label for="ac_title">公告标题</label></td>
													<td class="value">
														<input id="ac_title" class=" input-text" type="text">
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_type">公告主题</label></td>
													<td class="value">
														<select id="ac_type">
															<option value="0">--请选择主题--</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_for">面向商家</label></td>
													<td class="value">
														<select id="ac_for">
															<option value="0">全部商家</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_status">状态</label></td>
													<td class="value">
														<select id="ac_status">
															<option value="0">暂不发布</option>
															<option value="1">发布中</option>
															<option value="2">失效</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_status">是否置顶</label></td>
													<td class="value">
														<select id="ac_is_top">
															<option value="0">否</option>
															<option value="1">是</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_content">公告内容</label></td>
													<td class="value">
														<script id="ac_content" type="text/plain" style="width:100%;height:400px;"></script>
													</td>
												</tr>
												<tr>
													<td class="label"> </td>
													<td class="value">
														<div style="text-align:right;">
															<button onclick="announcementHandler.preview(1)">预览</button>
															&nbsp;&nbsp;
															<button onclick="announcementHandler.create()">保存</button>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
						<div id="tab_3" style="display:none;">
							<div id="ac_sort_option" class="entry-edit">
								<div class="entry-edit-head">
									<h4 class="icon-head head-edit-form fieldset-legend">公告筛选</h4>
								</div>
								<div class="fieldset fieldset-wide">
									<div style="padding:5px;margin-bottom:20px;border:1px solid #d6d6d6;">
										<table>
											<tr>
												<td style="width:100px;padding:5px;">主题：</td>
												<td style="padding:5px;">
													<select id="sort_theme">
														<option value="0">全部主题</option>
													</select>
												</td>
											</tr>
											<tr>
												<td style="width:100px;padding:5px;">状态：</td>
												<td style="padding:5px;">
													<select id="sort_status">
														<option value="0">全部状态</option>
														<option value="1">暂不发布</option>
														<option value="2">发布中</option>
														<option value="3">失效</option>
													</select>
												</td>
											</tr>
											<tr>
												<td style="width:100px;padding:5px;">是否置顶：</td>
												<td style="padding:5px;">
													<select id="sort_is_top">
														<option value="0">全部</option>
														<option value="1">不置顶</option>
														<option value="2">置顶</option>
													</select>
												</td>
											</tr>
											<tr>
												<td style="width:100px;padding:5px;">筛选创建人：</td>
												<td style="padding:5px;">
													<select id="sort_creator">
														<option value="0">全部创建人</option>
													</select>
												</td>
											</tr>
											<tr>
												<td style="width:100px;padding:5px;">筛选修改时间：</td>
												<td style="padding:5px;">
													<label>开始日期 <input type="text" id="begin_date" placeholder="请选择日期" style="width:100px;"/></label>&nbsp;&nbsp;
													<label>结束日期 <input type="text" id="end_date" placeholder="请选择日期" style="width:100px;"/></label>&nbsp;&nbsp;
												</td>
											</tr>
											<tr>
												<td style="width:100px;padding:5px;"> </td>
												<td style="padding:5px;">
													<button onclick="pageHandler.bySort()">查询</button>
												</td>
											</tr>
										</table>
									</div>
									<div style="padding:5px;border:1px solid #d6d6d6;">
										<table>
											<tr>
												<td style="width:100px;padding:5px;">搜索：</td>
												<td style="padding:5px;">
													<input type="text" id="keyword" placeholder="关键字搜索" onkeydown="pageHandler.bySearch(event)"/>
													<button onclick="pageHandler.bySearch()">搜索</button>
												</td>
											</tr>
										</table>
									</div>
								</div>
							</div>
							<div id="ac_list" class="entry-edit">
								<div class="entry-edit-head">
									<h4 class="icon-head head-edit-form fieldset-legend">公告列表</h4>
								</div>
								<div class="fieldset fieldset-wide">
									<div>
										<div id="ac_list_pan"></div>
										<div style="margin-top:15px;">
											Page <input type="text" id="ipt_page" style="width:30px;text-align:center;" value="1" onchange="pageHandler.changePage(this.value)"/> of <span id="page_total">1</span> pages&nbsp;&nbsp;|&nbsp;&nbsp; View
											<select id="slct_pagesize" onchange="pageHandler.changePageSize(this.value)">
												<option value="10">10</option>
												<option value="20">20</option>
											</select> per page&nbsp;&nbsp;|&nbsp;&nbsp;Total <span id="rows_total">0</span> records found
										</div>
									</div>
								</div>
							</div>
							<div id="ac_edit" class="entry-edit" style="display:none;">
								<div class="entry-edit-head">
									<h4 class="icon-head head-edit-form fieldset-legend">商家公告编辑</h4>
								</div>
								<div class="fieldset fieldset-wide">
									<div class="hor-scroll">
										<table cellspacing="0" class="form-list">
											<tbody>
												<tr>
													<td class="label"><label for="meta_title">公告标题</label></td>
													<td class="value">
														<input id="edit_ac_title" class=" input-text" type="text">
														<input type="hidden" id="edit_ac_id" />
													</td>
												</tr>
												<tr>
													<td class="label"><label for="edit_ac_type">公告主题</label></td>
													<td class="value">
														<select id="edit_ac_type">
															<option value="0">--请选择主题--</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="edit_ac_for">面向商家</label></td>
													<td class="value">
														<select id="edit_ac_for">
															<option value="0">全部商家</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="edit_ac_status">状态</label></td>
													<td class="value">
														<select id="edit_ac_status">
															<option value="0">暂不发布</option>
															<option value="1">发布中</option>
															<option value="2">失效</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="ac_status">是否置顶</label></td>
													<td class="value">
														<select id="edit_ac_is_top">
															<option value="0">否</option>
															<option value="1">是</option>
														</select>
													</td>
												</tr>
												<tr>
													<td class="label"><label for="edit_ac_content">公告内容</label></td>
													<td class="value">
														<script id="edit_ac_content" type="text/plain" style="width:100%;height:400px;"></script>
													</td>
												</tr>
												<tr>
													<td class="label"> </td>
													<td class="value">
														<div style="text-align:right;">
															<button onclick="announcementHandler.preview(2)">预览</button>
															&nbsp;&nbsp;
															<button onclick="announcementHandler.back()">返回</button>
															&nbsp;&nbsp;
															<button onclick="announcementHandler.save()">保存</button>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<form id="preview_form" action="http://vendors.rumall.com/announcement/preview" method="post" target="_blank">
	<input type="hidden" id="preview_title" name="title"/>
	<input type="hidden" id="preview_content" name="content"/>
	<input type="hidden" id="preview_author" name="author"/>
</form>
<script type="text/javascript" src="<?php echo $this->getJsUrl('lib/jquery/jquery-1.11.3.min.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->getJsUrl('ueditor_1_4_3_2_utf8/ueditor.config.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->getJsUrl('ueditor_1_4_3_2_utf8/ueditor.all.min.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->getJsUrl('ueditor_1_4_3_2_utf8/lang/zh-cn/zh-cn.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->getJsUrl('jquery-ui-1.12.1/jquery-ui.min.js')?>"></script>
<script type="text/javascript">
jQuery.noConflict();
var formKey = '<?php echo Mage::getSingleton('core/session')->getFormKey();?>', author = '<?php echo $this->getAuthorUserName();?>';
function switchTab(btn, tab) {
	jQuery('.tab-item-link').removeClass('active');
	jQuery(btn).addClass('active');
	jQuery('#tab_' + tab).show().siblings().hide();
	if (tab == 2) {
		typeHandler.freshTypes();
	} else if (tab == 3) {
		jQuery('#ac_edit').hide();
		jQuery('#ac_sort_option').show();
		jQuery('#ac_list').show();
		typeHandler.freshTypes();
		pageHandler.init();
	}
}
var typeHandler = {
		edit: function(btn) {
			btn = jQuery(btn);
			btn.hide();
			btn.parent().siblings('.item_name').hide();
			btn.parent().siblings('.item_val').val(btn.parent().siblings('.item_name').text()).show();
			btn.siblings('.item_btn_save').show();
			btn.siblings('.item_btn_cancel').show();
		},
		save: function(btn) {
			var
				typeId = jQuery(btn).parents('.actype_list_item').attr('id').substr(5),
				name = jQuery(btn).parent().siblings('.item_val').val();
			btn = jQuery(btn);
			if (!/^\s*$/.test(name)) {
				jQuery.post('<?php echo $this->getUrl('*/index/editType', array('_current' => false));?>?isAjax=true', {id: typeId, name: name, form_key: formKey}, function(res) {
					if (res == 1) {
						btn.hide();
						btn.siblings('.item_btn_cancel').hide();
						btn.parent().siblings('.item_val').hide();
						btn.parent().siblings('.item_name').text(btn.parent().siblings('.item_val').val()).show();
						btn.siblings('.item_btn_edit').show();
					} else {
						alert('保存失败');
					}
				});
			}
		},
		cancel: function(btn) {
			btn = jQuery(btn);
			btn.hide();
			btn.siblings('.item_btn_save').hide();
			btn.parent().siblings('.item_val').hide();
			btn.parent().siblings('.item_name').show();
			btn.siblings('.item_btn_edit').show();
		},
		create: function(btn) {
			btn = jQuery(btn);
			btn.hide();
			btn.parent().siblings('.item_val').show();
			btn.siblings('.item_btn_save').show();
			btn.siblings('.item_btn_cancel').show();
		},
		saveCreate: function(btn) {
			btn = jQuery(btn);
			var name = btn.parent().siblings('.item_val').val();
			if (!/^\s*$/.test(name)) {
				jQuery.post('<?php echo $this->getUrl('*/index/createType', array('_current' => false));?>?isAjax=true', {name: name, form_key: formKey}, function(res) {
					if (res != '0') {
						btn.hide();
						btn.parent().siblings('.item_val').val('').hide();
						btn.siblings('.item_btn_save').hide();
						btn.siblings('.item_btn_cancel').hide();
						btn.siblings('.item_btn_create').show();
						var html = '<div id="type_' + res + '" class="actype_list_item">\
										<span class="item_name">' + name + '</span>\
										<input type="text" class="item_val" value="" style="display:none;"/>\
										<div class="item_btn_grp">\
											<button class="item_btn_edit" onclick="typeHandler.edit(this)">编辑</button>\
											<button class="item_btn_save" style="display:none;margin-left:5px;" onclick="typeHandler.save(this)">保存</button>\
											<button class="item_btn_cancel" style="display:none;margin-left:5px;" onclick="typeHandler.cancel(this)">取消</button>\
										</div>\
									</div>';
						jQuery('#actype_list').append(html);
					} else {
						alert('添加失败');
					}
				});
			}
		},
		cancelCreate: function(btn) {
			btn = jQuery(btn);
			btn.hide();
			btn.parent().siblings('.item_val').hide();
			btn.siblings('.item_btn_save').hide();
			btn.siblings('.item_btn_cancel').hide();
			btn.siblings('.item_btn_create').show();
		},
		freshTypes: function() {
			jQuery.post('<?php echo $this->getUrl('*/index/getTypes', array('_current' => false));?>?isAjax=true', {form_key: formKey}, function(res) {
				if (res.status == 1) {
					var html1 = '<option value="0">--请选择主题--</option>', html2 = '<option value="0">全部主题</option>';
					announcementHandler.types = [];
					for (var i in res.data) {
						if (typeof res.data[i] == 'object') {
							announcementHandler.types.push(res.data[i]);
							html1 += '<option value="' + res.data[i].id + '">' + res.data[i].name + '</option>';
							html2 += '<option value="' + res.data[i].id + '">' + res.data[i].name + '</option>';
						}
					}
					jQuery('#ac_type').html(html1);
					jQuery('#sort_theme').html(html2);
				}
			}, 'json');
		}
};
var announcementHandler = {
		types: [],
		create: function() {
			var
				title = jQuery('#ac_title').val(),
				type = jQuery('#ac_type').val(),
				acFor = jQuery('#ac_for').val(),
				status = jQuery('#ac_status').val(),
				isTop = jQuery('#ac_is_top').val(),
				content = acAddEditor.getContent();
			if (/^\s*$/.test(title)) {
				alert('标题不能为空');
			} else if (type == '0') {
				alert('请选择主题');
			} else if (content == '') {
				alert('内容不能为空');
			} else {
				jQuery.post('<?php echo $this->getUrl('*/index/createAnnouncement', array('_current' => false));?>?isAjax=true', {title: title, type: type, status: status, isTop: isTop, content: content, form_key: formKey}, function(res) {
					if (res == '1') {
						alert('保存成功');
						jQuery('#ac_title').val('');
						acAddEditor.setContent('');
					} else {
						alert('保存失败');
					}
				});
			}
		},
		listAnnouncements: function(rows) {
			var html = '', tmp = '';
			for (var i in rows) {
				if (typeof rows[i] == 'object') {
					if (rows[i].status == 0)
						tmp = ' <span style="color:blue;">[暂未发布]</span>';
					else if (rows[i].status == 1)
						tmp = ' <span style="color:red;">[发布中]</span>';
					else if (rows[i].status == 2)
						tmp = ' <span style="color:gray;">[失效]</span>';
					html += '<div id="ac_list_item_' + rows[i].id + '" class="ac_list_item">\
								<div class="ac_list_item_title">' + (rows[i].is_top == 1 ? ' <span style="color:red;">[置顶]</span>' : '') + '<span style="color:green;">[' + rows[i].name + ']</span> ' + rows[i].title + tmp + '</div>\
								<div class="ac_list_item_info">\
									<span class="ac_list_item_info"><span style="color:#444;">面向商家：</span>全部商家</span>\
									<span class="ac_list_item_info"><span style="color:#444;">创建人：</span>' + rows[i].create_by + '</span>\
									<span class="ac_list_item_info"><span style="color:#444;">创建时间：</span>' + rows[i].create_time + '</span>\
									<span class="ac_list_item_info"><span style="color:#444;">最后修改人：</span>' + rows[i].edit_by + '</span>\
									<span class="ac_list_item_info"><span style="color:#444;">最后修改时间：</span>' + rows[i].edit_time + '</span>\
								</div>\
								<div class="ac_list_item_content">' + rows[i].content + '</div>\
								<div class="ac_list_item_opt">\
									<button onclick="announcementHandler.edit(' + rows[i].id + ')">编辑</button>\
									<!--<button onclick="announcementHandler.remove(' + rows[i].id + ')">删除</button>-->\
								</div>\
							</div>';
				}
			}
			if (html == '') {
				html = '<div style="text-align:center;color:red;">查无记录...</div>';
			}
			jQuery('#ac_list_pan').fadeOut(400, function() {
				jQuery('#ac_list_pan').html(html).fadeIn(400);
			});
		},
		edit: function(id) {
			jQuery('#edit_ac_id').val(0);
			jQuery('#edit_ac_title').val('');
			jQuery('#edit_ac_type').html('<option value="0">--请选择主题--</option>');
			acEditEditor.setContent('');
			jQuery.post('<?php echo $this->getUrl('*/index/getAnnouncementDetail', array('_current' => false));?>?isAjax=true', {id: id, form_key: formKey}, function(res) {
				if (res.status == 1) {
					jQuery('#edit_ac_id').val(id);
					jQuery('#edit_ac_title').val(res.data.title);
					jQuery('#edit_ac_status').val(res.data.status);
					jQuery('#edit_ac_is_top').val(res.data.is_top);
					acEditEditor.setContent(res.data.content);
					var html = '<option value="0">--请选择主题--</option>';
					for (var i in announcementHandler.types) {
						if (typeof announcementHandler.types[i] != 'object') {
							continue;
						}
						if (announcementHandler.types[i].id == res.data.type_id)
							html += '<option value="' + announcementHandler.types[i].id + '" selected>' + announcementHandler.types[i].name + '</option>';
						else
							html += '<option value="' + announcementHandler.types[i].id + '">' + announcementHandler.types[i].name + '</option>';
					}
					jQuery('#edit_ac_type').html(html);
				} else {
					alert('获取数据出错');
				}
			}, 'json');
			jQuery('#ac_sort_option').hide();
			jQuery('#ac_list').hide();
			jQuery('#ac_edit').show();
		},
		back: function() {
			jQuery('#ac_edit').hide();
			jQuery('#ac_sort_option').show();
			jQuery('#ac_list').show();
		},
		save: function() {
			var
				id = jQuery('#edit_ac_id').val(),
				title = jQuery('#edit_ac_title').val(),
				type = jQuery('#edit_ac_type').val(),
				acFor = jQuery('#edit_ac_for').val(),
				status = jQuery('#edit_ac_status').val(),
				isTop = jQuery('#edit_ac_is_top').val(),
				content = acEditEditor.getContent('');
			if (/^\s*$/.test(title)) {
				alert('标题不能为空');
			} else if (type == '0') {
				alert('请选择主题');
			} else if (content == '') {
				alert('内容不能为空');
			} else {
				jQuery.post('<?php echo $this->getUrl('*/index/editAnnouncement', array('_current' => false));?>?isAjax=true', {id: id, title: title, type: type, status: status, isTop: isTop, content: content, form_key: formKey}, function(res) {
					if (res == '1') {
						alert('保存成功');
						jQuery('#ac_edit').hide();
						jQuery('#ac_sort_option').show();
						jQuery('#ac_list').show();
						pageHandler.fresh();
					} else {
						alert('保存失败');
					}
				});
			}
		},
		remove: function(id) {
			if (confirm('确定要删除此公告吗')) {
				jQuery.post('<?php echo $this->getUrl('*/index/removeAnnouncement', array('_current' => false));?>?isAjax=true', {id: id, form_key: formKey}, function(res) {
					if (res == '1') {
						pageHandler.fresh();
					} else {
						alert('获取数据出错');
					}
				});
			}
		},
		preview: function(type) {
			var title = '', content = '';
			if (type == 1) {
				title = jQuery('#ac_title').val();
				content = acAddEditor.getContent();
			} else {
				title = jQuery('#edit_ac_title').val();
				content = acEditEditor.getContent();
			}
			jQuery('#preview_title').val(title);
			jQuery('#preview_content').val(content);
			jQuery('#preview_author').val(author);
			jQuery('#preview_form').submit();
		},
		getSortData: function(type, status, isTop, creator, beginDate, endDate, page, pageSize, func) {
			var data = {};
			data.form_key = formKey;
			data.page = page;
			data.pageSize = pageSize;
			data.type = type;
			data.status = status;
			data.isTop = isTop;
			data.creator = creator;
			data.beginDate = beginDate;
			data.endDate = endDate;
			jQuery.post('<?php echo $this->getUrl('*/index/getAnnouncementsBySort', array('_current' => false));?>?isAjax=true', data, function(res) {
				if (typeof func == 'function') {
					func(res);
				}
			}, 'json');
		},
		getSearchData: function(keyword, page, pageSize, func) {
			var data = {};
			data.form_key = formKey;
			data.page = page;
			data.pageSize = pageSize;
			data.keyword = keyword;
			jQuery.post('<?php echo $this->getUrl('*/index/getAnnouncementsBySearch', array('_current' => false));?>?isAjax=true', data, function(res) {
				if (typeof func == 'function') {
					func(res);
				}
			}, 'json');
		},
		getCreators: function() {
			jQuery.post('<?php echo $this->getUrl('*/index/getCreators', array('_current' => false));?>?isAjax=true', {form_key: formKey}, function(res) {
				if (res.error == 0) {
					var html = '<option value="0">全部创建人</option>';
					for (var i in res.data) {
						if (typeof res.data[i] == 'string') {
							html += '<option value="' + res.data[i] + '">' + res.data[i] + '</option>';
						}
					}
					jQuery('#sort_creator').html(html);
				}
			}, 'json');
		}
};
var pageHandler = {
		queryData: {queryType: 'bySort', type: '0', status: '0', isTop: '0', creator: '0', beginDate: '', endDate: '', keyword: ''},
		page: 1,
		pageSize: 10,
		total: 0,
		pageTotal: 1,
		init: function() {
			announcementHandler.getCreators();
			jQuery('#sort_theme').val('0');
			jQuery('#sort_status').val('0');
			jQuery('#sort_is_top').val('0');
			jQuery('#sort_creator').val('0');
			jQuery('#begin_date').val('');
			jQuery('#end_date').val('');
			jQuery('#keyword').val('');
			jQuery('#ipt_page').val('1');
			jQuery('#slct_pagesize').val('10');
			pageHandler.page = 1;
			pageHandler.pageSize = 10;
			pageHandler.bySort();
		},
		freshDisplay: function(pageTotal, total) {
			jQuery('#page_total').text(pageTotal);
			jQuery('#rows_total').text(total);
		},
		changePage: function(page) {
			page = parseInt(page);
			if (!isNaN(page) && page > 0 && page <= pageHandler.pageTotal) {
				pageHandler.page = page;
				pageHandler.fresh();
			}
		},
		changePageSize: function(pageSize) {
			jQuery('#ipt_page').val('1');
			pageHandler.page = 1;
			pageHandler.pageSize = pageSize;
			pageHandler.fresh();
		},
		callBack: function(res) {
			pageHandler.total = res.total;
			pageHandler.pageTotal = Math.ceil(res.total / pageHandler.pageSize);
			pageHandler.freshDisplay(pageHandler.pageTotal, pageHandler.total);
			announcementHandler.listAnnouncements(res.data);
		},
		fresh: function() {
			if (pageHandler.queryData.queryType == 'bySort') {
				announcementHandler.getSortData(pageHandler.queryData.type, pageHandler.queryData.status, pageHandler.queryData.isTop, pageHandler.queryData.creator, pageHandler.queryData.beginDate, pageHandler.queryData.endDate, pageHandler.page, pageHandler.pageSize, pageHandler.callBack);
			} else if (pageHandler.queryData.queryType == 'bySearch') {
				announcementHandler.getSearchData(pageHandler.queryData.keyword, pageHandler.page, pageHandler.pageSize, pageHandler.callBack);
			}
		},
		bySort: function() {
			pageHandler.queryData.queryType = 'bySort';
			pageHandler.queryData.type = jQuery('#sort_theme').val();
			pageHandler.queryData.status = jQuery('#sort_status').val();
			pageHandler.queryData.isTop = jQuery('#sort_is_top').val();
			pageHandler.queryData.creator = jQuery('#sort_creator').val();
			pageHandler.queryData.beginDate = jQuery('#begin_date').val();
			pageHandler.queryData.endDate = jQuery('#end_date').val();
			if (pageHandler.queryData.beginDate != '' && !/^\d{4}-\d{2}-\d{2}$/.test(pageHandler.queryData.beginDate))
				alert('开始日期格式不正确');
			else if (pageHandler.queryData.endDate != '' && !/^\d{4}-\d{2}-\d{2}$/.test(pageHandler.queryData.endDate))
				alert('结束日期格式不正确');
			else if (pageHandler.queryData.beginDate != '' && pageHandler.queryData.endDate != '' && new Date(pageHandler.queryData.beginDate) > new Date(pageHandler.queryData.endDate))
				alert('结束日期不能早于开始日期');
			else {
				jQuery('#ipt_page').val('1');
				pageHandler.page = 1;
				announcementHandler.getSortData(pageHandler.queryData.type, pageHandler.queryData.status, pageHandler.queryData.isTop, pageHandler.queryData.creator, pageHandler.queryData.beginDate, pageHandler.queryData.endDate, pageHandler.page, pageHandler.pageSize, pageHandler.callBack);
			}
		},
		bySearch: function(e) {
			if (typeof e == 'undefined' || e.keyCode == 13) {
				pageHandler.queryData.queryType = 'bySearch';
				pageHandler.queryData.keyword = jQuery('#keyword').val();
				jQuery('#ipt_page').val('1');
				pageHandler.page = 1;
				announcementHandler.getSearchData(pageHandler.queryData.keyword, pageHandler.page, pageHandler.pageSize, pageHandler.callBack);
			}
		}
};
var acAddEditor = UE.getEditor('ac_content'), acEditEditor = UE.getEditor('edit_ac_content');
jQuery('#begin_date,#end_date').datepicker({
	dateFormat: "yy-mm-dd",
	firstDay: 0
});
</script>